<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        .laytable-cell-1-0-1 {
            display: inline-block;
            max-width: 120px;
            min-width: 60px;
            text-align: center;
            padding: 3px 8px;
            margin-right: 8px;
            background-color: #fff;
            font-size: 12px;
            color: #e64c62;
            border: 1px solid #e8e8e8;
            -webkit-box-shadow: 0 1px 5px 1px #f0f0f0;
            box-shadow: 0 1px 5px 1px #f0f0f0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            vertical-align: middle;
        }
    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>

</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <!-- 上方搜索栏 -->
        <fieldset class="table-search-fieldset">
            <legend>搜索</legend>
            <div class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px">公司</label>
                        <div class="layui-input-inline" style="width: 150px">
                            <input type="text" id="dept" autocomplete="off" class="layui-input"
                                   placeholder="股票代码/简称"/>
                        </div>
                        <label class="layui-form-label" style="width: 100px">标题</label>
                        <div class="layui-input-inline" style="width: 260px">
                            <input type="text" id="title" autocomplete="off" class="layui-input"
                                   placeholder="包含全部关键词 空格区分"/>
                        </div>
                        <label class="layui-form-label" style="width: 100px">正文</label>
                        <div class="layui-input-inline" style="width: 260px">
                            <input type="text" id="content" autocomplete="off" class="layui-input"
                                   placeholder="包含全部关键词 空格区分"/>
                        </div>
                    </div>
                    <!-- 搜索、清除按钮 -->
                    <div class="layui-inline">
                        <button type="button" class="layui-btn layui-btn-primary layui-border-green btn-user-action"
                                data-type="search">
                            <i class="layui-icon layui-icon-search"></i> 搜 索
                        </button>
                        <button type="button" class="layui-btn layui-btn-primary btn-user-action" data-type="refresh">
                            <i class="layui-icon layui-icon-refresh"></i> 清 除
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
        <!-- 表格 -->
        <table class="layui-hide" id="table-system-user" lay-filter="table-system-user"></table>
    </div>
</div>
<!--表格头部工具类（左上）-->
<script type="text/html" id="toolbar-table-user">
    <div class="layui-btn-container">
        <!-- 【刷新】-->
        <button class="layui-btn layui-btn-sm layuimini-btn-primary" lay-event="btn-user-reload"><i
                class="fa fa-refresh"></i></button>
    </div>
    <p style="padding-left:36px;color: #313133"> 检索结果：股票
        <font style="color: #f82727" id="code-num">0 </font>个 ，公告
        <font style="color: #f82727" id="doc-num">0 </font>条
    </p>
</script>
<!--表格每行末尾的操作按钮-->
<script type="text/html" id="tool-table-user">
    <a class="layui-btn layui-btn-xs" lay-event="user-star" id="user-star-id"><i class="fa fa-star"></i>收藏</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="table-details"><i class="fa fa-eye"></i> 详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="user-down"><i class="fa fa-download"></i>下载</a>
</script>
<!--引入JS文件-->
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="/lib/jsencrypt/jsencrypt.min.js" charset="utf-8"></script>
<script src="/lib/jsencrypt/rsa.js" charset="utf-8"></script>
<script>
    layui.use(['table', 'dropdown'], function () {
        let $ = layui.jquery,
            form = layui.form,
            dropdown = layui.dropdown,
            table = layui.table;

        let currPage = 1                    // 定义全局变量：记录当前页码
        // 表格
        let table_user = table.render({
            elem: '#table-system-user',     // 绑定的表格ID
            url: '/ipoSearch/search',       // 表格数据请求URL
            response: {statusCode: 200},    // 请求成功的返回码
            height: 'full-158',             // 表格高度：高度最大化减去差值
            toolbar: '#toolbar-table-user', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports'],  // 工具栏
            title: '系统用户数据表',           // 表名，导出数据的时候有用
            cols: [
                [
                    {type: "checkbox", width: 50},
                    {
                        field: 'secCodeStr',
                        title: '股票代码',
                        width: 150,
                        align: 'center',
                        class: 'searchCode',
                        sort: true
                    },
                    {field: 'title', title: '标题', width: '20%', align: 'center'},
                    {field: 'digest', title: '摘要', width: '38%', align: 'center'},
                    {field: 'pubdateStr', title: '公告日期', width: 200, align: 'center'},
                    {
                        fixed: 'right', title: '操作', align: 'center', templet: function (item) {
                            $("#code-num").html(item.stockNum);
                            $("#doc-num").html(item.size);
                            var tem = [];
                            if (!item.star) {
                                tem.push(" <a class=\"layui-btn layui-btn-xs\" lay-event=\"user-star\" id=\"user-star-id\"><i class=\"fa fa-star\"></i>收藏</a>");
                            }
                            tem.push("<a class=\"layui-btn layui-btn-xs layui-btn-normal\" lay-event=\"table-details\"><i class=\"fa fa-eye\"></i> 详情</a>");
                            tem.push("<a class=\"layui-btn layui-btn-xs\" lay-event=\"user-down\"><i class=\"fa fa-eye\"></i>源文件</a>")
                            return tem;
                        }
                    }
                ]
            ],
            page: true,
            done: function (res, curr, count) {
                // 此处修复bug：删除最后一页数据后，跳转至上一页
                if (res.data.length === 0 && curr > 1) {
                    table_user.reload({page: {curr: curr - 1}});
                }
                currPage = curr
            }
        });

        // 表格的搜索加载与刷新，几个参数的定义，详见如下注释！
        let active = {
            search: function () {
                //执行重载
                table.reload('table-system-user', {
                    page: {curr: 1},            // 页码
                    where: {                    // 检索数据
                        secCodes: $('#dept').val(),
                        title: $('#title').val(),
                        content: $('#content').val()
                    }
                });
            },
            // 刷新：从第一页开始，检索数据清空
            refresh: function () {
                //执行刷新
                table.reload('table-system-user', {
                    page: {curr: 1},                    // 页码
                    where: {username: "", account: ""}  // 检索数据清空
                });
                $('#inputUserName').val('')             // 检索栏输入的数据清空
                $('#inputUserAccount').val('')
            }
        };
        // 【搜索】【清除】按钮的响应事件
        $('.btn-user-action').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        // 【行操作】监听表格行末按钮
        table.on('tool(table-system-user)', function (obj) {
            let that = this;
            let data = obj.data;
            let layEvent = obj.event;
            switch (layEvent) {
                // 【收藏】按钮
                case "user-star":
                    let docId = data.doc_id;
                    $.post("/ipoSearch/saveStar", {
                        docId: docId
                    }, function (d) {
                        // 根据返回状态码输出提示信息，200 表示成功，其他表示失败
                        if (d.code === 200) {
                            layer.msg(d.msg, {time: 3000, icon: 1});
                            table_user.reload()
                        } else {
                            layer.msg(d.msg, {time: 3000, icon: 2});
                        }
                    });
                    break;
                // 【详情】按钮
                case "table-details":
                    layer.open({
                        type: 1,
                        shade: 0.2,
                        title: '信息详情',
                        skin: 'layui-layer-prompt',
                        shadeClose: true,
                        area: ['900px', '800px'],
                        content: "<div id=\"viewer-container\" style='height: 800px'></div>",
                        success: function (layero, index) {
                            // 数据库表详情
                            $("#viewer-container").html("<iframe src=\"https://weixin.qianlima.com/qlmYFB/pdf/web/viewer.html?file=https%3A%2F%2Fyfb-file.oss-cn-hangzhou.aliyuncs.com%2Findustry_reports%2F20240409%2F1712650317107.pdf%3FExpires%3D4866250320%26OSSAccessKeyId%3DLTAIOb2FQSkCEu7K%26Signature%3DYyX4l099xTc6E9WPmsgimF4ErMI%253D\" width=\"100%\" height=\"100%\" frameborder=\"no\" ,=\"\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" allowtransparency=\"yes\"></iframe>");
                        }
                    });
                    break;
                // 【下载】按钮
                case "user-down":
                    let url = data.localpath;
                    var fileName = data.title + ".pdf";

                    const link = document.createElement('a');
                    link.href = url;
                    link.download = fileName;
                    link.target = "_blank"; // 可选，如果希望在新窗口中下载文件，请取消注释此行
                    link.click();

                    URL.revokeObjectURL(url);

            }
        });


    });
</script>
</body>
</html>
